/* Copyright (c) [2024] [ylc]. Licensed under Apache-2.0 License. */

#ifndef I2CDRIVES_H
#define I2CDRIVES_H

#include "my_define.h"

//IIC从机状态
typedef enum {
    IIC_S_STA_IDLE = 0,
    IIC_S_STA_RECV,
    IIC_S_STA_SEND,
    IIC_S_STA_ACK,
    IIC_S_STA_WACK,
    IIC_S_STA_ACK_END,
    IIC_S_STA_PEND,
}sI2C_StaTypedef_e;

//IIC从机中断序号
typedef enum {
    IIC_S_IT_IDLE = 0,
    IIC_S_IT_START,
    IIC_S_IT_RECV,
    IIC_S_IT_SEND,
    IIC_S_IT_PEND,
}sI2C_CbTypedef_e;

typedef struct {
    unsigned char RxLen;
    unsigned char Sta;
    unsigned char BitId;
    unsigned char Value;   //字节缓冲
    unsigned char DevAddrGet;
    unsigned char DevAddrSet;

    void (*IIC_IO_INIT)(void);   //硬件IO初始化
    void (*IIC_SDA_H)(void);          //SDA_H
    void (*IIC_SDA_L)(void);          //SDA_L
    unsigned char   (*IIC_READ_SDA)(void);          //读SDA
    unsigned char   (*IIC_READ_SCL)(void);   	    //读SCL
    void (*IIC_CALLBACK)(sI2C_CbTypedef_e i2c_CbType);  
}sI2CTypedef_t;

//放到对应的边沿中断中
void i2c_Sda_H_Cb(sI2CTypedef_t* i2c);
void i2c_Sda_L_Cb(sI2CTypedef_t* i2c);
void i2c_Scl_H_Cb(sI2CTypedef_t* i2c);
void i2c_Scl_L_Cb(sI2CTypedef_t* i2c);


#endif
